package com.youku.controls
{
   import com.youku.plugins.toolboxV4.ToolboxFacade;
   import com.youku.GlobalService;
   import com.youku.GlobalServiceKeys;
   import com.youku.events.PluginEvent;
   import com.youku.events.PlayerControlEvent;
   import com.youku.conductor.ConductorState;
   import com.youku.PlayerConfig;
   import com.youku.data.PlayerConstant;
   
   public class ToolBoxV4Controller extends BasePluginController
   {
      
      public function ToolBoxV4Controller() {
         super();
         this.init();
      }
      
      private var _toolboxFacade:ToolboxFacade;
      
      override protected function init() : void {
         this._toolboxFacade = ToolboxFacade.getInstance();
         this._toolboxFacade.init(viewManager.pluginLayer,playerProxy);
         GlobalService.addService(GlobalServiceKeys.TOOLBOX_FACADE,this._toolboxFacade);
         playerProxy.addEventListener(PluginEvent.TOOLBOX_CLOSE,this.onToolBoxEvent);
         playerProxy.addEventListener(PluginEvent.TOOLBOX_QUALITY_CHANGE,this.onToolBoxEvent);
         playerProxy.addEventListener(PluginEvent.TOOLBOX_CONTINUOUS_CHANGE,this.onToolBoxEvent);
         playerProxy.addEventListener(PluginEvent.TOOLBOX_JUMP_CHANGE,this.onToolBoxEvent);
         playerProxy.addEventListener(PluginEvent.TOOLBOX_ADJUST_VALUE_CHANGE,this.onToolBoxEvent);
         playerProxy.addEventListener(PluginEvent.TOOLBOX_VOICE_CHANGE,this.onToolBoxEvent);
      }
      
      private function onToolBoxEvent(param1:PluginEvent) : void {
         var _loc2_:String = null;
         var _loc3_:Object = null;
         var _loc4_:* = false;
         var _loc5_:* = false;
         var _loc6_:String = null;
         switch(param1.type)
         {
            case PluginEvent.TOOLBOX_ADJUST_VALUE_CHANGE:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_CHANGE_ADJUST_PARAMETERS,param1.data));
               break;
            case PluginEvent.TOOLBOX_QUALITY_CHANGE:
               _loc2_ = param1.data.quality;
               if(conductor.currentState == ConductorState.ERROR)
               {
                  PlayerConfig.rootData.firstQuality = _loc2_;
                  facadeManager.playNewVideo(playerProxy.playerData.videoIdEncode,true);
               }
               else
               {
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_CHANGE_QUALITY,{"quality":_loc2_}));
               }
               break;
            case PluginEvent.TOOLBOX_CONTINUOUS_CHANGE:
               _loc3_ = new Object();
               _loc4_ = param1.data.continuous as Boolean;
               _loc3_.continuous = _loc4_?1:0;
               externalInterfaceProxy.onPlayerSet(_loc3_);
               PlayerConfig.rootData.continuous = _loc4_;
               break;
            case PluginEvent.TOOLBOX_JUMP_CHANGE:
               _loc5_ = param1.data.jump;
               PlayerConfig.rootData.jump = _loc5_;
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.COMMON_SET_JUMP,{"jump":_loc5_}));
               break;
            case PluginEvent.TOOLBOX_VOICE_CHANGE:
               _loc6_ = param1.data.voice;
               facadeManager.changeVoice(_loc6_);
               break;
            case PluginEvent.TOOLBOX_CLOSE:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.AFTER_CLOSE_PANELS,{"panel":PlayerConstant.PANEL_TOOLBOX}));
               break;
         }
      }
   }
}
